package emulator.hardware.nmos6502;

public class FloatHelper {
	
	public static double fromMFLPT(int[] bytes)
	{
		int exponent = bytes[0] - 160;
		double mantisse = 0;
		for (int i = 1; i < 5; i++)
			mantisse = mantisse * 0x100 + bytes[i];
		int sign = 1;
		if ((bytes[1] & 0x80) != 0)
			sign = -1;
		else
			mantisse += 2147483648.0;
		return sign * mantisse * Math.pow(2, exponent);
	}

	public static double fromFLPT(int[] bytes)
	{
		int exponent = bytes[0] - 160;
		double mantisse = 0;
		for (int i = 1; i < 5; i++)
			mantisse = mantisse * 0x100 + bytes[i];
		int sign = (bytes[5] > 127 ? -1 : 1);
		return sign * mantisse * Math.pow(2, exponent);
	}
}
